package api;

import java.util.HashMap;
import java.util.List;

import model.Manipulator;
import model.ManipulatorListener;

public class ProgramState {

	private HashMap<Manipulator, Boolean> manips = new HashMap<Manipulator, Boolean>();
	public ProgramState()
	{
		
	}
	public void addManipulator(Manipulator m)
	{
		manips.put(m, new Boolean(false));
		m.addListener(new stateListener());
	}
	public boolean isReadyToContinue()
	{
		boolean ok = true;
		for(Boolean b : manips.values())
		{
			if(!b.booleanValue())
			{
				ok = false;
				break;
			}
		}
		return ok;
	}
	private class stateListener implements ManipulatorListener
	{
		@Override
		public void dataReady(Manipulator manip, List<String> data) {
			
			for(String s : data){
				if(!manip.getInterpreter().isResponseGood(s))
				{
					return;
				}
			}
			manips.put(manip, new Boolean(true));
		}
		@Override
		public void dataSending(Manipulator manip, String command) {
			// TODO Auto-generated method stub
			
		}
	}
}
